package terra.network.packet.client;

import org.jboss.netty.buffer.ChannelBuffer;

import terra.network.packet.Packet;


public class RequestChatMessage extends Packet {

	public String message;
	public int objectId;
	
	public RequestChatMessage(int oId,String s2) {
		objectId = oId;
		message = s2;
	}

	public RequestChatMessage() {
	}

	@Override
	public ChannelBuffer toBuffer() {
		byte[] msg = stringToBytes(message);		
		ChannelBuffer buf = getNewBuffer(1+8+msg.length);
		buf.writeByte(getId());
		buf.writeInt(msg.length+4);
		buf.writeInt(objectId);
		buf.writeBytes(msg);
		msg = null;
		return buf;
	}

	@Override
	public Packet fromBuffer(ChannelBuffer buf) {
		int length = buf.readInt()-4;
		objectId = buf.readInt();
		byte[] msg = new byte[length];
		buf.readBytes(msg);
		message = bytesToString(msg);
		return this;
	}

	@Override
	public int getLength() {
		return 0;
	}

	@Override
	public boolean isDynamicLength() {
		return true;
	}

	@Override
	public byte getId() {
		return 4;
	}
	
	@Override
	public byte getPriority() {
		return PRIOR_NORMAL;
	}

}
